﻿
using System.Windows.Input;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UITesting;
using Mouse = Microsoft.VisualStudio.TestTools.UITesting.Mouse;
using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
using SDWorx.ICTCorp.TestAutomationFramework.WinFormsApplication;

namespace SDWorx.ICTCorp.TestAutomationFramework
{
    [CodedUITest]
    public class CalcTest
    {
        [TestMethod]
        public void SumOf1And2Is3()
        {
            // TODO: should be refactored to somthing like this:

            //Start.Run.Click();
            //Start.Run.Open.Type("calc.exe{enter}");
            //Calc.Click("1");
            //Calc.Click("+");
            //Calc.Click("2");
            //Calc.Click("=");
            //Assert.AreEqual("3, ", Calc.Result);
            //Calc.Close();



            // Click 'start' button
            TAF_WinWindow mUIStartWindow = new TAF_WinWindow("Start", "Button", "start", "");
            Mouse.Click(new TAF_WinButton(mUIStartWindow,"Start"));

            // Click 'Run...' menu item
            TAF_WinWindow mUIStartMenu = new TAF_WinWindow("", "ToolbarWindow32", "", "Application");
            TAF_WinMenu UiMn = new TAF_WinMenu(mUIStartMenu);
            Mouse.Click(new TAF_WinMenuItem(UiMn,"Run..."));

            // Select 'calc.exe' in 'Open:' combo box
            TAF_WinWindow mUIRunWindow = new TAF_WinWindow("Run", "#32770", "Run", "");
            TAF_WinWindow UiRunItemWindow = new TAF_WinWindow(mUIRunWindow);
            new TAF_WinComboBox(UiRunItemWindow,"Open:").EditableItem = "calc.exe";
            // Type '{Enter}' in 'Open:' text box
            Keyboard.SendKeys(new TAF_WinComboBox(UiRunItemWindow,"Open:"), "{enter}", ModifierKeys.None);

            // Find the APP
            TAF_WinWindow mUICalculatorWindow = new TAF_WinWindow("Calculator", "SciCalc", "Calculator", "");
            // Find the Window and menubar
            TAF_WinWindow UiWindow = new TAF_WinWindow(mUICalculatorWindow);
            TAF_WinTitleBar UiBar = new TAF_WinTitleBar(mUICalculatorWindow);
            // Click '1' button
            Mouse.Click(new TAF_WinButton(UiWindow,"1"));
            // Click '+' button
            Mouse.Click(new TAF_WinButton(UiWindow,"+"));
            // Click '2' button
            Mouse.Click(new TAF_WinButton(UiWindow,"2"));
            // Click '=' button
            Mouse.Click(new TAF_WinButton(UiWindow,"="));
            // Verify that 'Unknown Name' text box's property 'Text' equals '3, '
            Assert.AreEqual("3, ", new TAF_WinEdit(UiWindow,"").Text);

            // Click 'Close' button
            Mouse.Click(new TAF_WinButton(UiBar,"Close"));
        }
    }
}
